home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Mail / pine3.92 / pine / osdep / execview < prev    next >
Text File  |  1995-10-25  |  2KB  |  76 lines

  1. /* ----------------------------------------------------------------------
  2.    Execute the given mailcap command
  3.  
  4.   Args: cmd           -- the command to execute
  5.     image_file    -- the file the data is in
  6.     needsterminal -- does this command want to take over the terminal?
  7.   ----*/
  8. void
  9. exec_mailcap_cmd(cmd, image_file, needsterminal)
  10. char *cmd;
  11. char *image_file;
  12. int   needsterminal;
  13. {
  14.     char   *command = NULL,
  15.        *result_file = NULL,
  16.        *p;
  17.     char  **r_file_h;
  18.     PIPE_S *syspipe;
  19.     int     mode;
  20.  
  21.     p = command = (char *)fs_get((32 + strlen(cmd) + (2*strlen(image_file)))
  22.                  * sizeof(char));
  23.     if(!needsterminal)  /* put in background if it doesn't need terminal */
  24.       *p++ = '(';
  25.     sprintf(p, "%s ; rm -f %s", cmd, image_file);
  26.     p += strlen(p);
  27.     if(!needsterminal){
  28.     *p++ = ')';
  29.     *p++ = ' ';
  30.     *p++ = '&';
  31.     }
  32.     *p++ = '\n';
  33.     *p   = '\0';
  34.     dprint(9, (debugfile, "exec_mailcap_cmd: command=%s\n", command));
  35.  
  36.     mode = PIPE_RESET;
  37.     if(needsterminal)
  38.       r_file_h = NULL;
  39.     else{
  40.     mode       |= PIPE_WRITE | PIPE_STDERR;
  41.     result_file = temp_nam(NULL, "pine_cmd");
  42.     r_file_h    = &result_file;
  43.     }
  44.  
  45.     if(syspipe = open_system_pipe(command, r_file_h, NULL, mode)){
  46.     close_system_pipe(&syspipe);
  47.     if(needsterminal)
  48.       q_status_message(SM_ORDER, 0, 4, "VIEWER command completed");
  49.     else
  50.       display_output_file(result_file, "VIEWER", " command launched");
  51.     }
  52.     else
  53.       q_status_message1(SM_ORDER, 3, 4, "Cannot spawn command : %s", cmd);
  54.  
  55.     fs_give((void **)&command);
  56.     if(result_file)
  57.       fs_give((void **)&result_file);
  58. }
  59.  
  60.  
  61. /* ----------------------------------------------------------------------
  62.    Execute the given mailcap test= cmd
  63.  
  64.   Args: cmd -- command to execute
  65.   Returns exit status
  66.   
  67.   ----*/
  68. int
  69. exec_mailcap_test_cmd(cmd)
  70.     char *cmd;
  71. {
  72.     return(system(cmd));
  73. }
  74.  
  75.  
  76.